import { storeToRefs } from 'pinia';
import { CrawlAndDownload } from './../../wailsjs/go/main/App';
import { useGlobalStore } from './../store/global';
import { SetCurrentDocumentByUrl, GetTitleTable, GetContent } from './../../wailsjs/go/main/App'

export async function crawlHtmlByUrl(url: string, selector: string) {
	return CrawlAndDownload(url, selector)
}

export async function setCurrentUrl(url: string) {
	const { currentUrl } = storeToRefs(useGlobalStore())
	return SetCurrentDocumentByUrl(url).then(() => {
		currentUrl.value = url
	})
}

export async function getTitleTable(url: string, urlSelector: string, textSelector: string) {
	return GetTitleTable(url, urlSelector, textSelector)
}

export async function getContent(url: string, imgSelector: string, textSelector: string) {
	return GetContent(url, imgSelector, textSelector).then(res => res as GetContentResponseType)
}